import qs from 'qs';
import ajax from '@/utils/ajax/index';
import authService from '@/services/user/auth';
import config from '@/config';
import handleCatch from '@/api/handleCatch';

export default {
  updateStatusByToken(id, status, data) {
    return authService.getToken().then((token) => {
      return ajax.patch(config.ajaxApi+'/user/mutually/buy/'+id+'/update/status/'+status+'/token?token='+token, qs.stringify(data))
        .then((res) => res.data)
        .catch(handleCatch);
    });
  },
  updateResetMatchTimeByToken(id) {
    return authService.getToken().then((token) => {
      return ajax.patch(config.ajaxApi+'/user/mutually/buy/'+id+'/update/resetMatch/token?token='+token)
        .then((res) => res.data)
        .catch(handleCatch);
    });
  },
  findFristByIdAndToken(id) {
    return authService.getToken().then((token) => {
      return ajax.get(config.ajaxApi+'/user/mutually/buy/findFirst/'+id+'/token?token='+token)
        .then((res) => res.data)
        .catch(handleCatch);
    });
  },
  pagerByToken(limit = 10, page = 1) {
    return authService.getToken().then((token) => {
      return ajax.get(config.ajaxApi+'/user/mutually/buy/pager/token?token='+token+'&limit='+limit+'&page='+page)
        .then((res) => res.data)
        .catch(handleCatch);
    });
  },
  createByToken(data) {
    return authService.getToken().then((token) => {
      return ajax.post(config.ajaxApi+'/user/mutually/buy/token?token='+token, qs.stringify(data))
        .then((res) => res.data)
        .catch(handleCatch);
    });
  }
};
